﻿@model Wicresoft.UnifyShow2.Portal.Models.OpsAddModel
@{
    ViewBag.Title = "运维报告管理";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}


<div class="index_lr">
    <div class="index_lrA_title ui-icons">
        <h3>运维报告管理</h3>
    </div>
    <div class="index_pt_bg">
        
        @using (Html.BeginForm("Admin", "OpsReport", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <table>
                <tr>
                    <td><label>名称:</label></td>
                    <td>
                        @Html.EditorFor(model => model.DName)
                    </td>
                    <td><label>关键字:</label></td>
                    <td>
                        @Html.EditorFor(model => model.Keywords)
                    </td>
                    <td><label>文件:</label></td>
                    <td>
                        <input type="file" name="OpsFiles" id="OpsFiles" />
                    </td>
                    <td style="width:50px;"></td>
                    <td>
                        <input type="submit" name="submit" value="上传" />
                    </td>
                </tr>
            </table>
            <fieldset>
                <legend>地市：全选<input type="checkbox" value="全选" id="allSites" /></legend>
                <div id="sites">
                    @{
                        List<Wicresoft.UnifyShow2.Portal.Models.US_SiteAccessModel> uslist = Model.US_SiteAccessList;
                        for (int i = 0; i < uslist.Count; i++)
                        {
                            @Html.EditorFor(model => model.US_SiteAccessList[i].IsAccess);
                            @Html.HiddenFor(model => model.US_SiteAccessList[i].ID);
                            @Html.HiddenFor(model => model.US_SiteAccessList[i].Alias);
                            <label>@uslist[i].Alias &nbsp;</label>
                        }
                    }
                </div>
            </fieldset>
        }
    </div>
    <div class="index_lrA_title ui-icons">
        <h3>运维报告列表</h3>
    </div>
    <div class="index_pt_bg" id="ListDocuments">
    </div>
</div>


@section ScriptAndCss{
    <link href="../../Content/css/bsadmin.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function loadList() {
            $("#ListDocuments").load("@Url.Action("ListAdmin", "OpsReport")", function () {
                $(".deleteDoc", "#ListDocuments").click(function (e) {
                    var isContinue = confirm("你确定要删除这个文件吗？");
                    if (isContinue) {
                        $.post("@Url.Action("Delete", "OpsReport")", { id: $(this).attr("data-id") }, function () {
                            loadList();
                            alert("删除成功");
                            location.reload();
                        });
                    }
                    e.preventDefault();
                });
            });
        }

        $(document).ready(function () {
            loadList();
            $("form").submit(function () {
                var name = $("#DName").val();
                var file = $("#OpsFiles").val();
                var keywords = $("#Keywords").val();
                //至少选择一个地市
                var isContain = 0;
                var sites = $(":checkbox", "#sites");
                var siteLength = sites.length;
                for (var i = 0; i < siteLength; i++) {
                    if ($(sites[i]).attr("checked") == "checked") {
                        isContain = 1;
                    }
                }
                if (name == "") {
                    alert("名称为空，请输入名称!");
                    return false;
                }
                else if (file == "") {
                    alert("文件为空，请选择需要上传的文件!");
                    return false;
                }
                else if (keywords == "") {
                    alert("关键字为空，请输入关键字!");
                    return false;
                }
                else if (isContain == 0) {
                    alert("您还未选择该文件可见的地市，至少选择一个地市!");
                    return false;
                }
                else
                    return true;
            });

            $("#allSites").change(function () {
                var sites = $(":checkbox", "#sites");
                if ($(this).attr("checked") == "checked") {
                    sites.each(function () {
                        $(this).attr("checked", "checked");
                    });
                }
                else {
                    sites.each(function () {
                        $(this).removeAttr("checked");
                    });
                }
            });
        });

    </script>
}
